import {
	province_list,
	school_level,
	school_types
} from "@/utils/api/dict.js"
export default {
	showToast(title, time = 3000, mask = false) {
		uni.showToast({
			title: title,
			duration: time,
			icon: "none",
			mask: mask,
		})
	},
	hideLoading() {
		uni.hideLoading()
	},
	loadToShow(msg = '加载中') {
		uni.showToast({
			title: msg,
			icon: 'loading'
		})
	},
	readData: (key) => {
		return uni.getStorageSync(key);
	},
	clearData: (key) => {
		uni.clearStorage(key);
	},
	navLaunch(url) {
		uni.reLaunch({
			url: url
		})
	},
	showToast(msg = '') {
		uni.showToast({
			title: msg || '服务器错误',
			icon: "none",
			duration: 3000,
		})
	},
	processreArr(arr) {
		return Object.values(arr.reduce((acc, cur) => {
			const key = cur.major|| (cur.zyz || '') + (cur.sname || '');
			if (!acc[key]) {
				acc[key] = {
					...cur,
					yearsSet: new Set([cur.year]),
					yearsData: [{
						year: cur.year,
						majorPlan: cur.majorPlan,
						admission: cur.admission,
						avgGradeStr: cur.avgGradeStr,
						minGradeSeq: cur.minGradeSeq,
						seqGrade: cur.seqGrade,
						seq: cur.seq,
						gradeLine: cur.gradeLine,
						minGrade: cur.minGrade,
						avgGrade: cur.avgGrade,
						minGradeStr: cur.minGradeStr,
						avgGradeSeq: cur.avgGradeSeq,
						planSubmitAdmission: cur.planSubmitAdmission,
					}]
				};
			} else {
				if (!acc[key].yearsSet.has(cur.year)) {
					acc[key].yearsSet.add(cur.year);
					acc[key].yearsData.push({
						year: cur.year,
						majorPlan: cur.majorPlan,
						admission: cur.admission,
						avgGradeStr: cur.avgGradeStr,
						minGradeSeq: cur.minGradeSeq,
						seqGrade: cur.seqGrade,
						seq: cur.seq,
						gradeLine: cur.gradeLine,
						minGrade: cur.minGrade,
						avgGrade: cur.avgGrade,
						minGradeStr: cur.minGradeStr,
						avgGradeSeq: cur.avgGradeSeq,
						planSubmitAdmission: cur.planSubmitAdmission,
					});
				}
			}
			return acc;
		}, {}));
	},
	processryear(arr) {
		return Object.values(arr.reduce((acc, cur) => {
			const key = cur.year;
			if (!acc[key]) {
				acc[key] = {
					...cur,
					yearsSet: new Set([cur.year]),
					yearArr: [{
						majorPlan: cur.majorPlan,
						admission: cur.admission,
						avgGradeStr: cur.avgGradeStr,
						minGradeSeq: cur.minGradeSeq,
						gradeLine: cur.gradeLine,
						seqGrade: cur.seqGrade,
						seq: cur.seq,
						avgGrade: cur.avgGrade,
						avgGradeSeq: cur.avgGradeSeq,
						minGrade: cur.minGrade,
						minGradeSeq: cur.minGradeSeq
					}]
				};
			} else {
				if (!acc[key].yearsSet.has(cur.year)) {
					acc[key].yearsSet.add(cur.year);
					acc[key].yearsData.push({
						yearArr: [{
							majorPlan: cur.majorPlan,
							admission: cur.admission,
							avgGradeStr: cur.avgGradeStr,
							minGradeSeq: cur.minGradeSeq,
						}]
					});
				}
			}
			return acc;
		}, {}));


	},
	// 封装判学校的数据
	processArray(arr) {
		return Object.values(arr.reduce((acc, cur) => {
			const key = cur.sname || cur.major;
			if (!acc[key]) {
				acc[key] = {
					...cur,
					yearsSet: new Set([cur.year]),
					yearsData: [{
						year: cur.year,
						gradeLine: cur.gradeLine,
						seqGrade: cur.seqGrade,
						seq: cur.seq,
						avgGrade: cur.avgGrade,
						avgGradeSeq: cur.avgGradeSeq,
						minGrade: cur.minGrade,
						planSubmitAdmission: cur.planSubmitAdmission,
						minGradeSeq: cur.minGradeSeq
					}]
				};
			} else {
				if (!acc[key].yearsSet.has(cur.year)) {
					acc[key].yearsSet.add(cur.year);
					acc[key].yearsData.push({
						year: cur.year,
						gradeLine: cur.gradeLine,
						seq: cur.seq,
						seqGrade: cur.seqGrade,
						avgGrade: cur.avgGrade,
						avgGradeSeq: cur.avgGradeSeq,
						minGrade: cur.minGrade,
						minGradeSeq: cur.minGradeSeq,
						planSubmitAdmission: cur.planSubmitAdmission,
					});
				}
			}
			return acc;
		}, {}));
	},
	//传入省市代码筛选省
	province(arr, str) {
		let pro1 = arr.filter(item => item.id == str);
		let str2 = pro1[0].name
		return str2
	},
	//合并再选科目的数据
	processzxkm(arr) {
		return Object.values(arr.reduce((acc, cur) => {
			const key = cur.zxkm;
			if (!acc[key]) {
				acc[key] = {
					...cur,
					yearsSet: new Set([cur.year]),
					yearsData: [{
						year: cur.year,
						gradeLine: cur.gradeLine,
						seqGrade: cur.seqGrade,
						seq: cur.seq,
						avgGrade: cur.avgGrade,
						avgGradeSeq: cur.avgGradeSeq,
						minGrade: cur.minGrade,
						planSubmitAdmission: cur.planSubmitAdmission,
						minGradeSeq: cur.minGradeSeq
					}]
				};
			} else {
				if (!acc[key].yearsSet.has(cur.year)) {
					acc[key].yearsSet.add(cur.year);
					acc[key].yearsData.push({
						year: cur.year,
						gradeLine: cur.gradeLine,
						seq: cur.seq,
						planSubmitAdmission: cur.planSubmitAdmission,
						seqGrade: cur.seqGrade,
						avgGrade: cur.avgGrade,
						avgGradeSeq: cur.avgGradeSeq,
						minGrade: cur.minGrade,
						minGradeSeq: cur.minGradeSeq
					});
				}
			}
			return acc;
		}, {}));
	},

}